/**
 * Created by Administrator on 2019/9/13.
 */
function s() {
    let tr = document.querySelectorAll('#table.tr');
    // 总价
    let allCount = document.querySelector('#allCount');
    // 先让总价等于
    let allCountNum = 0
    for (let i = 0; i < tr.length;i++){
        // 单价
        var price = tr[i].children[2].children[0].innerHTML
        // 数量
        var num = tr[i].children[3].children[0].value
        // 小计
        var count = tr[i].children[4].children[0].innerHTML = (price * num).toFixed(2)
        console.log(conut)
        allCountNum += Number(count)
    }
    // 赋值总价，总价取小数点后2位
    allCount.innerHTML = allCountNum.toFixed(2)
}

s()

// 修改数量的功能
// 获取table中所有的input数量
let ipt = document.querySelectorAll('#table .num')
for (let  j = 0; j < ipt.length; j++){
    ipt[j].addEventListener('changr',s)
}

// 删除功能
let del = document.querySelectorAll(".del")
for (let k = 0;k<del.length;k++){
    del[k].addEventListener('click',function () {
        console.log(this.parentNode)
        var tbody = document.querySelector("#table tbody")
        console.log(tbody)
        // 根据父级删除子级
        tbody.removeChild(this.parentNode)
    })
}